package ai.tasks;

import misc.Constant;
import ai.AIConstant;
import ai.Trackable;
import ai.PathFinding;
import ai.AIUtil;
import ai.engine.AIUnit;
import ai.engine.Task;
import ai.engine.TaskDoer;
import ai.engine.factories.TaskFactory;
import engine.UnitAction;
import util.List;

public class ExploreTask extends Task {

	byte direction;

	public ExploreTask(short id, Trackable target) {
		super(id, TaskFactory.EXPLORE_TASK, AIUnit.class, "Explore", "",
				AIConstant.PRIORITY_VERY_WEAK, target, AIUtil.getCurrentAIP().exploreMin,
		AIUtil.getCurrentAIP().exploreMax);
	}

	public boolean isTaskSuitable(TaskDoer possibleTaskDoer) {
		//AIUnit possibleUnitDoer = (AIUnit) possibleTaskDoer;
		return true;
	}
	
	public short getFormula(TaskDoer possibleTaskDoer) {
		//AIUnit possibleUnitDoer = (AIUnit) possibleTaskDoer;
		return this.priority;
	}

	public byte getAction(TaskDoer taskDoer) {
		AIUnit unitDoer = (AIUnit) taskDoer;
		if (!this.assignedResources.contains(unitDoer))
			return UnitAction.SKIP;
		if (unitDoer.lastDirection == UnitAction.NONE)
			unitDoer.lastDirection = UnitAction.MOVE_ACTIONS[Constant.RANDOM
					.nextInt(UnitAction.MOVE_ACTIONS.length)];
		return PathFinding.getNextDirection(PathFinding.TYPE_EXPLORE,
				unitDoer, taskDoer);
	}

	public List getAdditionalResourcesNeeded() {
		// TODO Demander des ressources d'exploration
		return null;
	}
	
	public boolean isObjectiveAchieved() {
		return false; // TODO Toujours une tache d'exploration.. pour le
		// moment
	}

}
